﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Electronic_work_order.Model;
using Electronic_work_order.Interfacess.OA_Users;
namespace Electronic_work_order.Controllers
{

    [ApiController]
    public class OA_UsersController : ControllerBase
    {
       
        private readonly Interface_Usrs context;

        public OA_UsersController(Interface_Usrs usrs)
        {
            context = usrs;
        }
        [HttpGet]
        [Route("[controller]/GetUsers")]
        //查询人员并显示职位
        public IEnumerable<Users> GetUsers()
        {
            return context.GetUsers();
        }
        [HttpGet]
        [Route("[controller]/GetUsers_MoHu")]
        //根据名字模糊查询
        public IEnumerable<Users> GetUsers_MoHu(string UsersName)
        {
            return context.GetUsers_MoHu(UsersName);
        }
        [HttpPut]
        [Route("[controller]/UpdateState")]
        //删除人员（修改其状态）
        public int UpdateState(int UsersID)
        {
            return context.UpdateState(UsersID);
        }

        //查询zt 
        [HttpGet]
        [Route("[controller]/GetState")]
        public IEnumerable<UserState> GetState()
        {
          return  context.GetStates();
        }
        [HttpPost]
        [Route("[controller]/AddUsers")]
        //添加职员
        public int AddUsers(Users users)
        {
            if (context.AddUsers(users)>0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        [HttpPut]
        [Route("[controller]/UpdateUsers")]
        //修改职员信息;
        public int UpdateUsers(Users users)
        {
            if (context.UpdateUsers(users)>0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        [HttpGet]
        [Route("[controller]/GetOrganizationName")]
        //查询所有部门
        public IEnumerable<Users> GetOrganizationName()
        {
            return context.GetOrganizations();
        }

        //查询职位
  [HttpGet]
  [Route("[controller]/GetPositions")]
  public IEnumerable<Position> GetPositions()
        {
            return context.GetPositions();
        }
    }
}
